package com.apo1o.cmscore.controller;

import com.apo1o.cmscore.util.*;
import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Auther: Apo1o.
 * @Date: 2023/11/16-11-16-9:21
 * @Description： com.apo1o.cmscore.controller
 */
@RestController
@RequiredArgsConstructor
public class UploadController {
    private final OSSUtil ossUtil;
    private final QiniuOss qiniuOss;
    private final LocalUploadUtil localUploadUtil;

    /**
     *
     * @Author: Apo1o.
     * @param multipartFile
     * @return 返回一个url
     * @throws Exception
     */
    @ApiOperation(value = "上传")
//    @ApiImplicitParam(name = "上传方式 可供选择（七牛云/阿里云/本地）",paramType = "query")
    @PostMapping("upload")
    @SneakyThrows
    public Result upload(@RequestParam("img") MultipartFile multipartFile ) throws Exception {
            String method = "阿里云";
        if (method.equals("七牛云")){
            return Result.success(qiniuOss.fileToOSS(multipartFile));

        }else if (method.equals("阿里云")){
            return Result.success(ossUtil.picOSS(multipartFile));

        }else if (method.equals("本地")){
            return Result.success(localUploadUtil.fileToLocal(multipartFile));
        }
        return Result.failure(ResultCode.PATH_UPLOAD_FILE);

    }

}
